package com.exchange.web.interfaces.controller;

import java.util.List;

import com.exchange.redis.services.RedisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.exchange.common.annotation.Log;
import com.exchange.common.enums.BusinessType;
import com.exchange.interfaces.domain.ExchangeProcess;
import com.exchange.interfaces.service.IExchangeProcessService;
import com.exchange.common.core.controller.BaseController;
import com.exchange.common.core.page.TableDataInfo;
import com.exchange.common.core.domain.AjaxResult;
import com.exchange.common.utils.poi.ExcelUtil;

/**
 * 数据交换_待处理数据 信息操作处理
 * 
 * @author exchange
 * @date 2019-06-03
 */
@Controller
@RequestMapping("/interfaces/exchangeProcess")
public class ExchangeProcessController extends BaseController
{
    private String prefix = "interfaces/exchangeProcess";
	
	@Autowired
	private IExchangeProcessService exchangeProcessService;

	@Autowired
	private RedisService redisService;
	
	@RequiresPermissions("interfaces:exchangeProcess:view")
	@GetMapping()
	public String exchangeProcess()
	{
	    return prefix + "/exchangeProcess";
	}
	
	/**
	 * 查询数据交换_待处理数据列表
	 */
	@RequiresPermissions("interfaces:exchangeProcess:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ExchangeProcess exchangeProcess)
	{
		redisService.zCount("zset");
		redisService.zRange("zset",0,10,0,5);

		startPage();
        List<ExchangeProcess> list = exchangeProcessService.selectExchangeProcessList(exchangeProcess);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出数据交换_待处理数据列表
	 */
	@RequiresPermissions("interfaces:exchangeProcess:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExchangeProcess exchangeProcess)
    {
    	List<ExchangeProcess> list = exchangeProcessService.selectExchangeProcessList(exchangeProcess);
        ExcelUtil<ExchangeProcess> util = new ExcelUtil<ExchangeProcess>(ExchangeProcess.class);
        return util.exportExcel(list, "exchangeProcess");
    }
	
	/**
	 * 新增数据交换_待处理数据
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存数据交换_待处理数据
	 */
	@RequiresPermissions("interfaces:exchangeProcess:add")
	@Log(title = "数据交换_待处理数据", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ExchangeProcess exchangeProcess)
	{		
		return toAjax(exchangeProcessService.insertExchangeProcess(exchangeProcess));
	}

	/**
	 * 修改数据交换_待处理数据
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		ExchangeProcess exchangeProcess = exchangeProcessService.selectExchangeProcessById(id);
		mmap.put("exchangeProcess", exchangeProcess);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存数据交换_待处理数据
	 */
	@RequiresPermissions("interfaces:exchangeProcess:edit")
	@Log(title = "数据交换_待处理数据", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ExchangeProcess exchangeProcess)
	{		
		return toAjax(exchangeProcessService.updateExchangeProcess(exchangeProcess));
	}
	
	/**
	 * 删除数据交换_待处理数据
	 */
	@RequiresPermissions("interfaces:exchangeProcess:remove")
	@Log(title = "数据交换_待处理数据", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(exchangeProcessService.deleteExchangeProcessByIds(ids));
	}
	
}
